/*
 * Copyright (C) 2011 Macambira Team
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */
package com.googlecode.services;

import com.googlecode.control.*;
import com.googlecode.entity.Curso;
import com.googlecode.entity.Curso;
import com.googlecode.entity.Departamento;
import com.googlecode.entity.Departamento;
import com.googlecode.entity.Disciplina;
import com.googlecode.entity.Disciplina;
import com.googlecode.entity.Professor;
import com.googlecode.entity.Professor;
import com.googlecode.entity.Turma;
import com.googlecode.entity.Turma;
import com.googlecode.exception.CursoNaoEncontradoException;
import com.googlecode.exception.DepartamentoNaoEncontradoException;
import com.googlecode.exception.DisciplinaNaoEncontradaException;
import com.googlecode.exception.ImpossivelAdicionarException;
import com.googlecode.exception.ProfessorException;
import com.googlecode.exception.ProfessorNaoEncontradoException;
import com.googlecode.exception.TurmaNaoEncontradaException;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;


/**
 * Fachada - contém instancias de todas as classes do pacote Register
 *
 * @version 0.2 05 Out 2011
 * @author Italo Cesar | italo.fernandes@dce.ufpb.br
 */
public class Facade {
    
    private static Facade facade;
    private ControlProfessor cProfessor;
    private ControlCurso cCurso;
    private ControlDisciplina cDisciplina;
    private ControlDepartamento cDepartamento;
    private ControlTurma cTurma;
    private Professor professor;
    private Curso curso;
    private Departamento departamento;
    private Disciplina disciplina;
    private Turma turma;
    private DisciplinaOferecidaNoSemestre dos;
    
    public Facade(){
        this.cProfessor = new ControlProfessor();
        this.cCurso = new ControlCurso();
        this.cDisciplina = new ControlDisciplina();
        this.cDepartamento = new ControlDepartamento();
        this.cTurma = new ControlTurma();
        this.curso = new Curso();
        this.professor = new Professor();
        this.departamento = new Departamento();
        this.disciplina = new Disciplina();
        this.turma = new Turma();
        this.dos = new DisciplinaOferecidaNoSemestre();
    }
 
    public static Facade getInstance() {
		if( facade == null ){
			facade = new Facade(); 
		}
		return facade;
	}
    
    /*Métodos de ControlCurso*/
    
    public void addCurso(Curso curso) throws SQLException {
        try {
            cCurso.addCurso(curso);
        } catch (SQLException ex) {
            throw new RuntimeException();
        }
    }
    
    public Curso getCursoNome(String nome) throws SQLException {
        try {
            return cCurso.getCursoNome(nome);
        } catch (SQLException ex) {
            throw new RuntimeException();   
        }
    }
    
    public Curso getCursoID(String id) throws SQLException {
        try {
            return cCurso.getCursoId(id);
        } catch (SQLException ex) {
            throw new RuntimeException();
        }
  
    }
    
    public void removeCursoNome(String nome) throws SQLException {
        try {
            cCurso.removeCursoNome(nome);
        } catch (SQLException ex) {
            throw new RuntimeException();
        }
    }
    
    public void removeCursoID(String id) throws SQLException {
        try {
            cCurso.removeCursoId(id);
        } catch (SQLException ex) {
            throw new RuntimeException();
        }
    }
    
    public int getSize() {
        return cCurso.getSize();
    }
    
    public List getListaCursos() {
        return cCurso.getListaCursos();
    }
    
    
    /*Métodos de ControlDepartamento*/
    
    public void addDepartamento(Departamento d) throws SQLException {
        try {
            cDepartamento.addDepartamento(d);
        } catch (SQLException ex) {
            throw new RuntimeException();
        }
    }
    
    public Departamento getDepartamentoNome(String nome) throws SQLException {
        try {
            return cDepartamento.getDepartamentoNome(nome);
        } catch (SQLException ex) {
            throw new RuntimeException();
        }

    }
    
    public List getListDepartamento() {
        return cDepartamento.getListDepartamento();
    }
    
    public Departamento getDepartamentoId(String id) throws SQLException {
        try {
            return cDepartamento.getDepartamentoId(id);
        } catch (SQLException ex) {
            throw new RuntimeException();
        }

    }
    
    public void removeDepartamentoNome(String nome) throws SQLException {
        try {
            cDepartamento.removeDepartamentoNome(nome);
        } catch (SQLException ex) {
            throw new RuntimeException();
        }
    }
    
    public void removeDepartamentoId(String id) throws SQLException {
        try {
            cDepartamento.removeDepartamentoNome(id);
        } catch (SQLException ex) {
            throw new RuntimeException();
        }
    }
    
    public int getSizeDepartamento() {
        return cDepartamento.getSizeDepartamento();
    }
    
    
    /*Métodos de ControlDisciplina*/
    
    public void addDisciplina(Disciplina di) throws SQLException {
        try {
            cDisciplina.addDisciplina(di);
        } catch (SQLException ex) {
            throw new RuntimeException();
        }
    }
    
    public Disciplina getDisciplinaNome(String nome) throws SQLException {
        try {
            return cDisciplina.getDisciplinaNome(nome);
        } catch (SQLException ex) {
            throw new RuntimeException();
        }
  
    }
    
    public Disciplina getDisciplinaId(String id) throws SQLException {
        try {
            return cDisciplina.getDisciplinaId(id);
        } catch (SQLException ex) {
            throw new RuntimeException();
        }
 
    }
    public void removeDisciplinaNome(String nome) throws SQLException {
        try {
            cDisciplina.removerDisciplinaNome(nome);
        } catch (SQLException ex) {
            throw new RuntimeException();
        }
    }
    
    public void removeDisciplinaId(String id) throws SQLException {
        try {
            cDisciplina.removerDisciplinaId(id);
        } catch (SQLException ex) {
            throw new RuntimeException();
        }
    }
    
    public void updateDisciplina(Disciplina di) throws SQLException {
        try {
            cDisciplina.updateDisciplina(di);
        } catch (SQLException ex) {
            throw new RuntimeException();
        }
    }
    
    public int getSizeDisciplina() {
        return cDisciplina.getSize();
    }
    
    
    /*Métodos de ControlProfessor*/
    
    public void addProfessor(Professor p) throws SQLException {
        try {
            cProfessor.addProfessor(p);
        } catch (SQLException ex) {
            throw new RuntimeException();
        }
    }
    
    public Professor getProfessorID(String id) throws SQLException {
        try {
            return cProfessor.getProfessorID(id);
        } catch (SQLException ex) {
            throw new RuntimeException();
        }
            
    }

    public Professor getProfessorNome(String nome) throws SQLException {
        try {
            return cProfessor.getProfessorNome(nome);
        } catch (SQLException ex) {
            throw new RuntimeException();
        }
       
    }
    
    public void removeProfessorNome(String nome) throws SQLException {
        try {
            cProfessor.removeProfessorNome(nome);
        } catch (SQLException ex) {
            throw new RuntimeException();
        }

    }
    
    public void removeProfessorID(String id) throws SQLException {
        try {
            cProfessor.removeProfessorID(id);
        } catch (SQLException ex) {
            throw new RuntimeException();
        }
     
    }
    
    public List<Professor> getListaProfessores() {
        
            return cProfessor.getListaProfessores();

    }
    
    public Map<String, Professor> getMapProfessores() {
        
            return cProfessor.getMapProfessores();
        
    }
    
    public int listGetSize() {
        return cProfessor.listGetSize();
    }
    
    public int mapGetSize() {
        return cProfessor.mapGetSize();
    }
    
    public Professor getObjetoProfessor(Professor procurado) throws SQLException {
        try {
            return cProfessor.getObjetoProfessor(procurado);
        } catch (SQLException ex) {
            throw new RuntimeException();
        }
    }
    
    
    /*Métodos de ControlTurma*/
    
    public void addTurma(Turma t) throws SQLException {
        try {
            cTurma.addTurma(t);
        } catch (SQLException ex) {
            throw new RuntimeException();
        }
    }
    
    public void addDisciplinaTurma(String nomeTurma, Disciplina di) throws SQLException {
        try {
            cTurma.addDisciplinaTurma(nomeTurma, di);
        } catch (SQLException ex) {
            throw new RuntimeException();
        }
 
    }
    
    public boolean verificaProfessorDisciplina(Disciplina disciplina) {
        return cTurma.verificaProfessorDisciplina(disciplina);
    }
    
    public boolean execVerificaProfessorDisciplina() {
        return cTurma.execVerificaProfessorDisciplina();
    }
    
    public List<Turma> getTurma() {
        return cTurma.getTurma();
    }
    
    public Turma getTurmaId(String id) throws SQLException {
        try {
            return cTurma.getTurmaId(id);
        } catch (SQLException ex) {
            throw new RuntimeException();
        }

        
    }
    
    public Turma getTurmaNome(String nome) throws SQLException {
        try {
            return cTurma.getTurmaNome(nome);
        } catch (SQLException ex) {
            throw new RuntimeException();
        }
 
    }
    
    public void removeTurmaNome(String nome) throws SQLException {
        try {
            cTurma.removerTurmaNome(nome);
        } catch (SQLException ex) {
            throw new RuntimeException();
        }
    }
    
    public void removeTurmaId(String id) throws SQLException {
        try {
            cTurma.removerTurmaId(id);
        } catch (SQLException ex) {
            throw new RuntimeException();
        }
    }
    
    public void updateTurma(Turma t) throws SQLException {
        try {
            cTurma.updateTurma(t);
        } catch (SQLException ex) {
            throw new RuntimeException();
        }
    }
    
    public void addProfessorTurma(Professor p, String nomeTurma) throws SQLException {
        try {
            cTurma.addProfessorTurma(p, nomeTurma);
        } catch (SQLException ex) {
            throw new RuntimeException();
        }
    }
    
    public int getSizeTurmas() {
        return cTurma.getSize();
    }
    
    /*Métodos da classe DisciplinaOferecidaNoSemestre*/
    
    public List getDisciplinaOferecidaNoSemestre() {
        return dos.getDisciplinaOferecidaNoSemestre();
    }
    
    public void setDisciplinaOferecidaNoSemestre(List novaLista) {
        dos.setDisciplinaOferecidaNoSemestre(novaLista);
    }
    
    public void addDisciplinaOferecidaNoSemestre(Disciplina di) {
        dos.addDisciplinaOferecidaNoSemestre(di);
    }
    
    public void removerPorNomeDisciplinaOferecidaNoSemestre(String nome) {
        dos.removerPorNomeDisciplinaOferecidaNoSemestre(nome);
    }
    
    public void removerPorIDDisciplinaOferecidaNoSemestre(String id) {
        dos.removerPorIDDisciplinaOferecidaNoSemestre(id);
    }
    
    public Disciplina buscarPorNomeDisiciplinaOferecidaNoSemestre(String nome) {
        return dos.buscarPorNomeDisiciplinaOferecidaNoSemestre(nome);
    }
    
    public Disciplina buscarPorIDDisiciplinaOferecidaNoSemestre(String id) {
        return dos.buscarPorIDDisiciplinaOferecidaNoSemestre(id);
    }
    
    public int getSizeDisciplinasOferecidasNoSemestre() {
        return dos.getSize();
    }
    
    public List<Turma> getListaTurmas(){
        return cTurma.getListaTurmas();
    }
    
    public List<Disciplina> getListaDisciplinas(){
        return cDisciplina.getListaDisciplinas();
    }
}
